import os
from utils import ReadXml
from tqdm import tqdm

SrcDir = r"/media/fang/TOSHIBA EXT/Temp/600_300/M"
MaxH = 300
MaxW = 600

LabelIsAPoint = []
LabelOverSize = []
LabelLessThanZero = []

for root, dirs, files in os.walk(SrcDir):
    for file in tqdm(files):
        if file[-1] == 'l':
            Locations = ReadXml(root + "/" + file)
            for Location in Locations:
                if Location[0] == Location[2] or Location[1] == Location[3]:
                    if file not in LabelIsAPoint:
                        LabelIsAPoint.append(file)
                if Location[2] > MaxW or Location[3] > MaxH:
                    if file not in LabelOverSize:
                        LabelOverSize.append(file)
                if Location[0] < 0 or Location[1] < 0 or Location[2] < 0 or Location[3] < 0:
                    LabelLessThanZero.append(file)
if len(LabelIsAPoint) == 0 and len(LabelOverSize) == 0 and len(LabelLessThanZero) == 0:
    print("All xmls is normal")
else:
    if len(LabelIsAPoint) != 0:
        print("%d xmls's label is a point" % len(LabelIsAPoint))
        print(LabelIsAPoint)
    if len(LabelOverSize) != 0:
        print("%d xmls's label over the edge" % len(LabelOverSize))
        print(LabelOverSize)
    if len(LabelLessThanZero) != 0:
        print("%d xmls's label less than zero" % len(LabelLessThanZero))
        print(LabelLessThanZero)

